package com.qf.service;

import com.qf.dto.VoucherDto;
import com.qf.mapper.VoucherMapper;
import com.qf.pojo.Voucher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VoucherService {

    @Autowired
    private VoucherMapper voucherMapper;


    public Map<String ,Object> getList(VoucherDto dto) {
        Map<String ,Object> result=new HashMap<>();
        if(dto.getPage()!=null){ dto.setPage((dto.getPage()-1)*dto.getPageSize()); }

        //获取当前时间的年月日时分秒格式的string类型的日期
        //localDate获取年月日
        dto.setCurrentDate(LocalDateTime.now().toString());
        List<Voucher> list= voucherMapper.getList(dto);

        Integer count=voucherMapper.getListCount(dto);
        result.put("data",list);
        result.put("count",count);
        return  result;
    }


    public void delete(Integer id) {
        voucherMapper.delete(id);

    }

    public void add(Voucher voucher) {

         voucher.setCreatTime(new Date());
        voucherMapper.add(voucher);
    }
}
